import django_filters
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend

from users.models import *
from businesses.models import *


class LevelFilter(django_filters.rest_framework.FilterSet):
    '''客户经理料过滤'''

    merchant_id = django_filters.BaseInFilter(field_name='merchantenter__merchant_id', lookup_expr='in')

    class Meta:
        model = Level
        fields = ('merchant_id',)


class CustomerUserFilter(django_filters.rest_framework.FilterSet):
    '''C端用户资料过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = CustomerUser
        fields = ('create_time_begin', 'create_time_end')


class ManagerUserFilter(django_filters.rest_framework.FilterSet):
    '''客户经理料过滤'''

    is_active = django_filters.BaseInFilter(field_name='is_active', lookup_expr='in')
    role_id = django_filters.BaseInFilter(field_name='role_id', lookup_expr='in')
    is_developer = django_filters.BaseInFilter(field_name='is_developer', lookup_expr='in')
    is_agreement = django_filters.BaseInFilter(field_name='is_agreement', lookup_expr='in')

    class Meta:
        model = User
        fields = ('is_active', 'role_id', 'is_developer', 'is_agreement')


class CustomerUserViceFilter(django_filters.rest_framework.FilterSet):

    is_wyh_customer = django_filters.BaseInFilter(field_name='is_wyh_customer', lookup_expr='in')
    is_subscribe = django_filters.BaseInFilter(field_name='is_subscribe', lookup_expr='in')
    obtain_point_min = django_filters.NumberFilter(field_name="obtain_point", lookup_expr='gte')
    obtain_point_max = django_filters.NumberFilter(field_name="obtain_point", lookup_expr='lte')

    class Meta:
        model = CustomerUserVice
        fields = ('is_wyh_customer', 'is_subscribe', 'obtain_point_min', 'obtain_point_max')


class CustomerUserViceInviterRecordFilter(django_filters.rest_framework.FilterSet):
    '''添加用户申请单过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    inviter_time_begin = django_filters.DateTimeFilter(field_name="inviter_time__date", lookup_expr='gte')
    inviter_time_end = django_filters.DateTimeFilter(field_name="inviter_time__date", lookup_expr='lte')
    qrcode_id = django_filters.BaseInFilter(field_name='qrcode_id', lookup_expr='in')
    is_inviter = django_filters.BaseInFilter(field_name='is_inviter', lookup_expr='in')

    class Meta:
        model = CustomerUserViceInviterRecord
        fields = ('create_time_begin', 'create_time_end', 'qrcode_id', 'inviter_time_begin', 'inviter_time_end', 'is_inviter')


class JoinCustomizeActivityFilter(django_filters.rest_framework.FilterSet):

    is_join = django_filters.BaseInFilter(field_name='is_join', lookup_expr='in')
    count = django_filters.BaseInFilter(field_name='count', lookup_expr='in')
    customizeactivity_id = django_filters.BaseInFilter(field_name='customizeactivity_id', lookup_expr='in')
    join_time_begin = django_filters.DateTimeFilter(field_name="join_time__date", lookup_expr='gte')
    join_time_end = django_filters.DateTimeFilter(field_name="join_time__date", lookup_expr='lte')

    class Meta:
        model = JoinCustomizeActivity
        fields = ('is_join', 'join_time_begin', 'join_time_end', 'count', 'customizeactivity_id')


class BindCardOrderFilter(django_filters.rest_framework.FilterSet):

    order_status = django_filters.BaseInFilter(field_name='order_status', lookup_expr='in')
    prize_status = django_filters.BaseInFilter(field_name='prize_status', lookup_expr='in')
    bank_type = django_filters.BaseInFilter(field_name='bank_type_sign', lookup_expr='in')
    customizeactivity_id = django_filters.BaseInFilter(field_name='customizeactivity_id', lookup_expr='in')
    received_time_begin = django_filters.DateTimeFilter(field_name="customizeactivityflipcards__received_time__date", lookup_expr='gte')
    received_time_end = django_filters.DateTimeFilter(field_name="customizeactivityflipcards__received_time__date", lookup_expr='lte')

    class Meta:
        model = BindCardOrder
        fields = ('order_status', 'prize_status', 'customizeactivity_id', 'received_time_begin', 'received_time_end', 'bank_type')